package com.baizhi.comtroller;

import com.baizhi.entity.T_user;
import com.baizhi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 登陆
     */
    @PostMapping("login")
    String login(T_user user, HttpSession session){
        T_user obj = userService.login(user);
        if(obj != null){
            session.setAttribute("user", obj);
            return "redirect:/file/showAll";
        }else {
            return "redirect:/index";
        }
    }


    @GetMapping("test")
    public void test(){
        System.err.println("已运行");
    }
}
